package com.drools.userguide._2_twoRules;

import com.drools.userguide._1_onlyOneRule.Applicant;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.StatelessKieSession;

import java.util.Arrays;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class Test {

    /**
     * 这个插入2个Data，实际上也是转换为Command
     */
    @org.junit.Test
    public void test() {
        KieServices kieServices = KieServices.Factory.get();
        KieContainer kContainer = kieServices.getKieClasspathContainer();
        StatelessKieSession kSession = kContainer.newStatelessKieSession();
        Applicant applicant = new Applicant("Mr John Smith", 16);
        Application application = new Application();
        assertTrue(application.isValid());
        kSession.execute(Arrays.asList(new Object[]{application, applicant}));
        assertFalse(application.isValid());
    }

    /**
     * 也可以批量插入同一类型的实例，这个对无状态session没有影响，就跟入参一样
     */
    @org.junit.Test
    public void testTwoSameTypeObj() {
        KieServices kieServices = KieServices.Factory.get();
        KieContainer kContainer = kieServices.getKieClasspathContainer();
        StatelessKieSession kSession = kContainer.newStatelessKieSession();
        Applicant applicant = new Applicant("Mr John Smith", 16);
        Applicant applicant1 = new Applicant("Jack", 20);
        kSession.execute(Arrays.asList(new Object[]{applicant1, applicant}));
        assertFalse(applicant.isValid());
        assertFalse(applicant1.isValid());
    }
}
